<!--
 * @Descripttion: 多图上传
 * @Author: zhoujj
 * @Date: 2021-07-05 16:09:18
 * @LastEditors: zhoujj
 * @LastEditTime: 2022-05-24 15:01:56
-->
<template>
  <div v-if="item">
    <el-form ref="form" :rules="rules" :model="form" label-width="120px">
      <el-form-item :label="item.title" prop="value">
        <el-upload
          :multiple="true"
          list-type="picture-card"
          :action="uploadUrl"
          :headers="uploadHeader"
          :on-remove="handleRemove"
          :file-list="form.value"
          :on-success="handleAvatarSuccess"
        >
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    export default {
        props: ['item', 'number', 'uploadHeader', 'uploadUrl'],
        data () {
            return {
                form: {
                    value: []
                },
                rules: {
                    value: [
                        {
                            required: this.item.must,
                            message: this.item.msg,
                            trigger: 'change'
                        }
                    ]
                }
            }
        },
        methods: {
            emitParent () {
                this.$emit('changeComponent', {
                    number: this.number,
                    type: this.item.type,
                    value: this.form.value
                })
            },
            // 上传成功
            handleAvatarSuccess (res, file, fileList) {
                this.form.value = fileList
                this.$refs.form.clearValidate()
                this.emitParent()
            },
            // 删除
            handleRemove (file, fileList) {
                this.form.value = fileList
                this.emitParent()
            }
        },
        mounted () {
            this.form = {
                ...this.form,
                ...this.item
            }
        }
    }
</script>

<style></style>
